using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

namespace SMS.HangFireApi
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>().ConfigureAppConfiguration((builderContext, config) =>
                {
                    var env = builderContext.HostingEnvironment;
                    var rootPath = "Config/";
                    config.AddJsonFile($"{rootPath}appsettings.json");
                    config.AddJsonFile($"{rootPath}appsettings.{env.EnvironmentName}.json");
                    config.AddJsonFile($"{rootPath}autofac.json");
                    config.AddJsonFile($"{rootPath}autofac.{env.EnvironmentName}.json");
                    config.AddEnvironmentVariables();
                });
            })
            .UseServiceProviderFactory(new AutofacServiceProviderFactory());
    }
}
